<%= javascript_include_tag "prototype" %>
<div id="display_by">
<% if params[:id] != "home" %>
Browse by:
<% if @result[:type] != :title%>
<%= link_to_remote ("Title", :url => {:action => :display_by, :type => "title"}) %>
<% else %>
<span style="font-weight:bold">Title</span>
<% end %>

<% if @result[:type] != :categoryList%>
<%= link_to_remote ("Category", :url => {:action => :display_by, :type => "categoryList"}) %>
<% else %>
<span style="font-weight:bold">Category</span>
<% end %>

<% if @result[:type] != :recentlyupdated%>
<%= link_to_remote ("Recently Updated", :url => {:action => :display_by, :type => "recentlyupdated"}) %>
<% else %>
<span style="font-weight:bold">Recently Updated</span>
<% end %>

<% if @result[:type] != :recentlyadded%>
<%= link_to_remote ("Recently Added", :url => {:action => :display_by, :type => "recentlyadded"}) %>
<% else %>
<span style="font-weight:bold">Recently Added</span>
<% end %>

<% if @result[:type] != :popular%>
<%= link_to_remote ("Most Popular", :url => {:action => :display_by, :type => "popular"}) %>
<% else %>
<span style="font-weight:bold">Most Popular</span>
<% end %>
<% end %>
<h1><%= @result[:heading]%></h1>
<div style="border:grey 1px solid">
  <table width="100%" align="center">
<!--     <tr><td><h1><%= @result[:heading]%></h1></td></tr> -->
    <% if @result[:type] == :title %>
    <% if @result[:data].length > 0%>
    <tr>
      <th>Title</th>
      <th># of Views</th>
      <th>Last Updated</th>
    </tr>
    <% end %>
    <% for aLetter in @result[:data].keys.sort %>
    <tr width="100%">
      <td class="letterHeader"><h2><%= aLetter.upcase %></h2></td>
      <td class="letterHeader"></td><td class="letterHeader"></td>
    </tr>
    <% i = 0 %>
    <% for webcomic in @result[:data][aLetter] %>
    <% if i % 2 == 0 %>
    <% x = "even" %>
    <% else %>
    <% x = "odd" %>
    <% end %>
    <tr>
      <%= "<td class=\"" + x + "\" width=\"70%\">"%>
        <%= link_to webcomic.title, webcomic%>
      </td>
      <%= "<td class=\"" + x + "\" width=\"15%\">"%>
        <%= webcomic.number_of_views %>
      </td>
      <%= "<td class=\"" + x + "\" width=\"15%\">"%>
        <%= webcomic.updated_at.localtime.strftime("%m-%d-%Y") %>
      </td>
    </tr>
    <% i += 1 %>
    <% end %>
    <% end %>

    <% elsif @result[:type] == :recentlyupdated || @result[:type] == :popular || @result[:type] == :recentlyadded%>
    <% if @result[:data].length > 0%>
    <tr>
      <th>Title</th>
      <th># of Views</th>
      <th>Last Updated</th>
    </tr>
    <% end %>
    <% i = 0 %>
    <% for webcomic in @result[:data] %>
    <% if i % 2 == 0 %>
    <% x = "even" %>
    <% else %>
    <% x = "odd" %>
    <% end %>
    <tr>
      <%= "<td class=\"" + x + "\" width=\"70%\">"%>
        <%= link_to webcomic.title, webcomic%>
      </td>
      <%= "<td class=\"" + x + "\" width=\"15%\">"%>
        <%= webcomic.number_of_views %>
      </td>
      <%= "<td class=\"" + x + "\" width=\"15%\">"%>
        <%= webcomic.updated_at.localtime.strftime("%m-%d-%Y") %>
      </td>
    </tr>
    <% i += 1 %>    
    <% end %>
    <% elsif @result[:type] == :categoryList %>
    <tr><td>
      <table align="center" >
        <tr>
          <% i = 0 %>
          <% j = 0 %>
          <% for category in @result[:data] do %>
          <% if i % 2 == 0%>
          <td width="100px" class="even" >
            <%= link_to_remote(category.name, :url => {:action => :display_webcomics_in_category, :cat_id => category.id, :type => "category", :id=>1}) %>
          </td>
          <% else %>
          <td width="100px" class="odd" >
            <%= link_to_remote(category.name, :url => {:action => :display_webcomics_in_category, :cat_id => category.id, :type => "category", :id=>1}) %>
          </td>
          <% end %>
          <% i = i+1 %>
          <% if (i == 8)%>
          <% i = 0 %>
          <% j += 1 %>
            </tr>
            <tr>
          <% end %>
          <% end %>
        </tr>
      </table>
      <div align="center">
      <%= link_to_remote("View all", :url => {:action => :display_webcomics_in_category, :type => "allcategories", :id => 1}) %>
      </div>
    </tr></td>
    <% end %>
  </table>

  <%= render :partial => "webcomics/webcomics_in_categories" %>
</div>

</div>